#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include "absyn.h"

using namespace std;
extern int yyparse(void);
extern FILE* yyin;
TreeNode savedTree;
vector<string> errMsg;



int main(int argc, char **argv)
{
    if(argc != 3)
    {
        cout<<"please input like : ./main x.spl y.asm"<<endl;
        exit(1);
    }
    char* input = argv[1];
    string output = argv[2];
    FILE *fp = fopen(input, "r");
    if(fp == NULL)
    {
        cout<<"can not open file "<<input<<endl;
        exit(1);
    }
    yyin = fp;
    cout<<"compile begin"<<endl;
    yyparse();
    fclose(fp);
    cout<<"compile end"<<endl;
	if(errMsg.size()==0)
	{
        cout<<"===========A=B=S=T=R=A=C=T===T=R=E=E============="<<endl;
		savedTree->printTree(savedTree,0);
	}
	else
		for(int i = 0; i < errMsg.size(); i++)
            cout<<"Error: "<<errMsg.at(i)<<endl;
    return 0;
}
